package net.acoinWork.dynRender.configParse.xmlModel;

import org.jdom2.Element;
import org.jdom2.Namespace;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author xusk
 * @Date: 15/12/31 上午11:15
 */
public final class CommandCol implements XmlEleAssembly {
    private String engine;
    private List<Command> commands = new ArrayList<Command>();

    public List<Command> getCommands() {
        return Collections.unmodifiableList(commands);
    }

    public String getEngine() {
        return engine;
    }

    @Override
    public void assemble(Element element, Namespace namespace) {
        final String engine = element.getAttributeValue("engine");
        this.engine = engine == null ? "VELOCITY" : engine;
        for (Element ele : element.getChildren("cmd", namespace)) {
            Command command = new Command();
            command.assemble(ele, namespace);
            commands.add(command);
        }
    }

    @Override
    public String toString() {
        return "CommandCol{" +
                ", commands=" + commands +
                '}';
    }
}
